<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>easykf-2.04: example-005.cc</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">easykf-2.04
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">example-005.cc</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><span class="comment">/* example-005.cc</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * Copyright (C) 2011-2014 Jeremy Fix</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * This program is free software; you can redistribute it and/or modify</span></div>
<div class="line"><span class="comment"> * it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><span class="comment"> * the Free Software Foundation; either version 3 of the License, or (at</span></div>
<div class="line"><span class="comment"> * your option) any later version.</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * This program is distributed in the hope that it will be useful, but</span></div>
<div class="line"><span class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span></div>
<div class="line"><span class="comment"> * General Public License for more details.</span></div>
<div class="line"><span class="comment"> * </span></div>
<div class="line"><span class="comment"> * You should have received a copy of the GNU General Public License</span></div>
<div class="line"><span class="comment"> * along with this program; if not, write to the Free Software</span></div>
<div class="line"><span class="comment"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">/* In this example, we use a 2-12-2 MLP network to learn the Mackay Robot arm data  */</span></div>
<div class="line"><span class="comment">/* Here , we consider a vectorial output, it extends example-004                    */</span></div>
<div class="line"><span class="comment">/* In addition to the weights and biases, we also parametrize the transfer function */</span></div>
<div class="line"><span class="comment">/* The results are saved in example-005-results.data, a 4 column datafile.          */</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;cmath&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;fstream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;time.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;algorithm&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="ukf_8h.html">ukf.h</a>&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">using namespace </span>ukf::parameter;</div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#define VERBOSE true</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define NB_INPUTS 2</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define NB_HIDDEN 8</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#define NB_OUTPUTS 2</span></div>
<div class="line"><span class="preprocessor"></span></div>
<div class="line"><span class="comment">/*****************************************************/</span></div>
<div class="line"><span class="comment">/*            Definition of the MLP                  */</span></div>
<div class="line"><span class="comment">/*****************************************************/</span></div>
<div class="line"><span class="keywordtype">double</span> transfer(<span class="keywordtype">double</span> x, <span class="keywordtype">double</span> a, <span class="keywordtype">double</span> b, <span class="keywordtype">double</span> u , <span class="keywordtype">double</span> c)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordflow">return</span> a / (1.0 + exp(-b * (x-u)))+c;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="comment">/*double transfer(double x)</span></div>
<div class="line"><span class="comment">{</span></div>
<div class="line"><span class="comment">    return 2.0 / (1.0 + exp(-x)) - 1.0;</span></div>
<div class="line"><span class="comment">}*/</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> my_func(gsl_vector * param, gsl_vector * input, gsl_vector * output)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordtype">double</span> y[NB_HIDDEN];</div>
<div class="line">    <span class="keywordtype">double</span> z=0.0;</div>
<div class="line"></div>
<div class="line">    <span class="keywordtype">double</span> a0 = gsl_vector_get(param,(NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS);</div>
<div class="line">    <span class="keywordtype">double</span> b0 = gsl_vector_get(param,(NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS+1);</div>
<div class="line">    <span class="keywordtype">double</span> u0 = gsl_vector_get(param,(NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS+2);</div>
<div class="line">    <span class="keywordtype">double</span> c0 = gsl_vector_get(param,(NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS+3);</div>
<div class="line"></div>
<div class="line">    <span class="keywordtype">double</span> a1 = gsl_vector_get(param,(NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS+4);</div>
<div class="line">    <span class="keywordtype">double</span> b1 = gsl_vector_get(param,(NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS+5);</div>
<div class="line">    <span class="keywordtype">double</span> u1 = gsl_vector_get(param,(NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS+6);</div>
<div class="line">    <span class="keywordtype">double</span> c1 = gsl_vector_get(param,(NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS+7);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0 ; i &lt; NB_HIDDEN ; i++)</div>
<div class="line">        y[i] = 0.0;</div>
<div class="line"></div>
<div class="line">    <span class="keywordtype">int</span> i_param = 0;</div>
<div class="line">    gsl_vector_set_zero(output);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0 ; j &lt; NB_HIDDEN ; j++)</div>
<div class="line">    {</div>
<div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> k = 0 ; k &lt; NB_INPUTS ; k++)</div>
<div class="line">        {</div>
<div class="line">            y[j] += gsl_vector_get(param, i_param) * gsl_vector_get(input, k);</div>
<div class="line">            i_param++;</div>
<div class="line">        }</div>
<div class="line">        y[j] += gsl_vector_get(param, i_param);</div>
<div class="line">        i_param++;</div>
<div class="line">        y[j] = transfer(y[j], 1.0, 1.0, 0.0, 0.0);</div>
<div class="line">        <span class="comment">//y[j] = transfer(y[j]);</span></div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">// First output</span></div>
<div class="line">    z = 0.0;</div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0 ; j &lt; NB_HIDDEN ; j++)</div>
<div class="line">    {</div>
<div class="line">        z += gsl_vector_get(param,i_param) * y[j];</div>
<div class="line">        i_param++;</div>
<div class="line">    }</div>
<div class="line">    z += gsl_vector_get(param, i_param);</div>
<div class="line">    i_param++;</div>
<div class="line"></div>
<div class="line">    z = transfer(z,a0,b0,u0,c0);</div>
<div class="line">    <span class="comment">//z = transfer(z);</span></div>
<div class="line">    gsl_vector_set(output, 0, z);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Second output</span></div>
<div class="line">    z = 0.0;</div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> j = 0 ; j &lt; NB_HIDDEN ; j++)</div>
<div class="line">    {</div>
<div class="line">        z += gsl_vector_get(param,i_param) * y[j];</div>
<div class="line">        i_param++;</div>
<div class="line">    }</div>
<div class="line">    z += gsl_vector_get(param, i_param);</div>
<div class="line">    i_param++;</div>
<div class="line"></div>
<div class="line">    z = transfer(z,a1,b1,u1,c1);</div>
<div class="line">    <span class="comment">//z = transfer(z);</span></div>
<div class="line">    gsl_vector_set(output, 1, z);</div>
<div class="line"></div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="comment">// Structure holding a sample : the joint angles and the cartesian position</span></div>
<div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div>
<div class="line">    <span class="keywordtype">float</span> theta;</div>
<div class="line">    <span class="keywordtype">float</span> phi;</div>
<div class="line">    <span class="keywordtype">float</span> x;</div>
<div class="line">    <span class="keywordtype">float</span> y;</div>
<div class="line">} Sample;</div>
<div class="line"></div>
<div class="line"></div>
<div class="line"><span class="comment">/*****************************************************/</span></div>
<div class="line"><span class="comment">/*                    main                           */</span></div>
<div class="line"><span class="comment">/*****************************************************/</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[]) {</div>
<div class="line"></div>
<div class="line">    srand(time(NULL));</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Definition of the parameters and state variables</span></div>
<div class="line">    <a name="_a0"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html">ukf_param</a> p;</div>
<div class="line">    <a name="_a1"></a><a class="code" href="structukf_1_1parameter_1_1ukf__state.html">ukf_state</a> s;</div>
<div class="line"></div>
<div class="line">    p.<a name="a2"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#afdb1ce39c4a72e31df41314e2e4c4090">n</a> = (NB_INPUTS+1) * NB_HIDDEN + (NB_HIDDEN+1)* NB_OUTPUTS + 8 ;</div>
<div class="line">    p.<a name="a3"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a6672a2098cafbda39c6bd4946ca701ad">no</a> = NB_OUTPUTS;</div>
<div class="line">    p.<a name="a4"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a6226f46479a98fdeb1321d49680e76ed">kpa</a> = 3.0 - p.<a class="code" href="structukf_1_1parameter_1_1ukf__param.html#afdb1ce39c4a72e31df41314e2e4c4090">n</a>;</div>
<div class="line">    p.<a name="a5"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a41e15863dacadc709c856810fec793da">alpha</a> = 1e-2;</div>
<div class="line">    p.<a name="a6"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a3afc7edee6fb3dd28849f2219c079b30">beta</a> = 2.0;</div>
<div class="line"></div>
<div class="line">    <a name="_a7"></a><a class="code" href="classukf_1_1parameter_1_1EvolutionNoise.html">EvolutionNoise</a> * evolution_noise = <span class="keyword">new</span> <a name="_a8"></a><a class="code" href="classukf_1_1parameter_1_1EvolutionAnneal.html">EvolutionAnneal</a>(1e-3,0.999, 1e-8);</div>
<div class="line">    <span class="comment">//EvolutionNoise * evolution_noise = new EvolutionRLS(1e-4,0.9995);</span></div>
<div class="line">    <span class="comment">//EvolutionNoise * evolution_noise = new EvolutionRobbinsMonro(1e-3,1e-4);</span></div>
<div class="line">    p.<a name="a9"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a84f1c71ab2cd9fc6063790e9942637bd">evolution_noise</a> = evolution_noise;</div>
<div class="line"></div>
<div class="line">    p.<a name="a10"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#ade187fc4a6cf6c6e9a1fcb5cf8898985">observation_noise</a> = 1e-1; <span class="comment">// Observation noise</span></div>
<div class="line">    p.<a name="a11"></a><a class="code" href="structukf_1_1parameter_1_1ukf__param.html#a898c9583fba45551ae39213dd2b212ba">prior_pi</a> = 1.0; <span class="comment">// Initializition of the covariance of the parameters</span></div>
<div class="line"></div>
<div class="line">    <span class="comment">// Initialization of the state and parameters</span></div>
<div class="line">    <a name="a12"></a><a class="code" href="namespaceukf_1_1parameter.html#ad83710f24d64d3b511ff60aa4fc90f03">ukf_init</a>(p,s);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Initialize the parameter vector to some random values</span></div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0 ; i &lt; p.<a class="code" href="structukf_1_1parameter_1_1ukf__param.html#afdb1ce39c4a72e31df41314e2e4c4090">n</a> ; i++)</div>
<div class="line">        gsl_vector_set(s.<a name="a13"></a><a class="code" href="structukf_1_1parameter_1_1ukf__state.html#aff3014ff4ffec72ecff69f533540e88a">w</a>,i,0.01*(2.0 * rand()/<span class="keywordtype">double</span>(RAND_MAX-1) - 1.0));</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Allocate the input/output vectors</span></div>
<div class="line">    gsl_vector * xi = gsl_vector_alloc(NB_INPUTS);</div>
<div class="line">    gsl_vector * yi = gsl_vector_alloc(NB_OUTPUTS);</div>
<div class="line"></div>
<div class="line">    <span class="comment">// Define some limit conditions for the learning</span></div>
<div class="line">    <span class="keywordtype">double</span> errorBound = 8e-3;</div>
<div class="line">    <span class="keywordtype">int</span> nbStepsLimit = 1000;</div>
<div class="line">    <span class="keywordtype">double</span> error = 2*errorBound;;</div>
<div class="line"></div>
<div class="line">    <span class="comment">/***********************************************/</span></div>
<div class="line">    <span class="comment">/*****        Load the training data set   *****/</span></div>
<div class="line">    <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">    std::vector&lt; Sample &gt; samples;</div>
<div class="line">    FILE * inputs_file = fopen (<span class="stringliteral">&quot;Data/Mackay-inputs.data&quot;</span>,<span class="stringliteral">&quot;r&quot;</span>);</div>
<div class="line">    FILE * outputs_file = fopen (<span class="stringliteral">&quot;Data/Mackay-outputs.data&quot;</span>,<span class="stringliteral">&quot;r&quot;</span>);</div>
<div class="line">    <span class="keywordtype">char</span> c;</div>
<div class="line"></div>
<div class="line">    <span class="keywordtype">double</span> mintheta=0.0;</div>
<div class="line">    <span class="keywordtype">double</span> maxtheta=0.0;</div>
<div class="line">    <span class="keywordtype">double</span> minphi=0.0;</div>
<div class="line">    <span class="keywordtype">double</span> maxphi =0.0;</div>
<div class="line">    <span class="keywordtype">bool</span> is_init = <span class="keyword">false</span>;</div>
<div class="line">    <span class="keywordflow">do</span></div>
<div class="line">    {</div>
<div class="line">        Sample s;</div>
<div class="line">        fscanf(inputs_file,<span class="stringliteral">&quot;%f&quot;</span>,&amp;s.theta);</div>
<div class="line">        fscanf(inputs_file,<span class="stringliteral">&quot;%f&quot;</span>,&amp;s.phi);</div>
<div class="line">        fscanf(outputs_file,<span class="stringliteral">&quot;%f&quot;</span>,&amp;s.x);</div>
<div class="line">        fscanf(outputs_file,<span class="stringliteral">&quot;%f&quot;</span>,&amp;s.y);</div>
<div class="line">        <span class="keywordflow">if</span>(!is_init)</div>
<div class="line">        {</div>
<div class="line">            mintheta = s.theta;</div>
<div class="line">            maxtheta = s.theta;</div>
<div class="line">            minphi = s.phi;</div>
<div class="line">            maxphi = s.phi;</div>
<div class="line">            is_init = <span class="keyword">true</span>;</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span></div>
<div class="line">        {</div>
<div class="line">            mintheta = s.theta &lt; mintheta ? s.theta : mintheta;</div>
<div class="line">            maxtheta = s.theta &gt; maxtheta ? s.theta : maxtheta;</div>
<div class="line">            minphi = s.phi &lt; minphi ? s.phi : minphi;</div>
<div class="line">            maxphi = s.phi &gt; maxphi ? s.phi : maxphi;</div>
<div class="line">        }</div>
<div class="line">        samples.push_back(s);</div>
<div class="line">        c = getc (inputs_file);</div>
<div class="line">    } <span class="keywordflow">while</span>(c != EOF);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span>(VERBOSE) std::cout &lt;&lt; <span class="stringliteral">&quot;I found : &quot;</span> &lt;&lt; samples.size() &lt;&lt; <span class="stringliteral">&quot; samples &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">    <span class="keywordflow">if</span>(VERBOSE) std::cout &lt;&lt; mintheta &lt;&lt; <span class="stringliteral">&quot; &lt; theta &lt; &quot;</span> &lt;&lt; maxtheta &lt;&lt; std::endl;</div>
<div class="line">    <span class="keywordflow">if</span>(VERBOSE) std::cout &lt;&lt; minphi &lt;&lt; <span class="stringliteral">&quot; &lt; phi &lt; &quot;</span> &lt;&lt; maxphi &lt;&lt; std::endl;</div>
<div class="line"></div>
<div class="line">    <span class="comment">/***********************************************/</span></div>
<div class="line">    <span class="comment">/***** Iterate the learning on the samples *****/</span></div>
<div class="line">    <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">    <span class="keywordtype">int</span> epoch = 0;</div>
<div class="line">    error = 2 * errorBound;</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">while</span>( epoch &lt;= nbStepsLimit &amp;&amp; error &gt; errorBound)</div>
<div class="line">    {</div>
<div class="line">        <span class="comment">// Iterate on the samples</span></div>
<div class="line">        std::random_shuffle(samples.begin(), samples.end());</div>
<div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j = 0 ; j &lt; samples.size() ; j++)</div>
<div class="line">        {</div>
<div class="line">            gsl_vector_set(xi,0,samples[j].theta);</div>
<div class="line">            gsl_vector_set(xi,1,samples[j].phi);</div>
<div class="line"></div>
<div class="line">            gsl_vector_set(yi, 0, samples[j].x);</div>
<div class="line">            gsl_vector_set(yi, 1, samples[j].y);</div>
<div class="line"></div>
<div class="line">            <a name="a14"></a><a class="code" href="namespaceukf_1_1parameter.html#aa7af8ceffba2f9288b2d7b86ed57159f">ukf_iterate</a>(p, s, my_func,xi,yi);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">// Evaluate the RMS error</span></div>
<div class="line">        error = 0.0;</div>
<div class="line">        <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j = 0 ; j &lt; samples.size() ; j++)</div>
<div class="line">        {</div>
<div class="line">            gsl_vector_set(xi,0,samples[j].theta);</div>
<div class="line">            gsl_vector_set(xi,1,samples[j].phi);</div>
<div class="line"></div>
<div class="line">            my_func(s.w,xi,yi);</div>
<div class="line"></div>
<div class="line">            error += pow(samples[j].x - gsl_vector_get(yi,0),2.0)+pow(samples[j].y - gsl_vector_get(yi,1),2.0);</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        error = sqrt(error /  <span class="keywordtype">double</span>(samples.size()));</div>
<div class="line">        <span class="keywordflow">if</span>(VERBOSE)</div>
<div class="line">            std::cout &lt;&lt; <span class="stringliteral">&quot;Epoch &quot;</span> &lt;&lt; epoch &lt;&lt; <span class="stringliteral">&quot; error = &quot;</span> &lt;&lt; error &lt;&lt; std::endl;</div>
<div class="line">        epoch++;</div>
<div class="line">    }</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot;Run on &quot;</span> &lt;&lt; epoch &lt;&lt; <span class="stringliteral">&quot; epochs ; RMS = &quot;</span> &lt;&lt; error &lt;&lt; <span class="stringliteral">&quot;\n&quot;</span> &lt;&lt; std::endl ;</div>
<div class="line"></div>
<div class="line">    <span class="comment">/***********************************************/</span></div>
<div class="line">    <span class="comment">/****     Save the results                  ****/</span></div>
<div class="line">    <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">    std::ofstream outfile(<span class="stringliteral">&quot;example-005.data&quot;</span>);</div>
<div class="line">    std::cout &lt;&lt; <span class="stringliteral">&quot; You can plot them using e.g. gnuplot : &quot;</span> &lt;&lt; std::endl;</div>
<div class="line">    <span class="comment">//std::cout &lt;&lt; &quot; gnuplot Data/plot-example-005.gplot ; gv Output/example-005-y1.ps ; gv Output/example-005-y2.ps &quot; &lt;&lt; std::endl;</span></div>
<div class="line">    <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0 ; i &lt; samples.size() ; i++)</div>
<div class="line">    {</div>
<div class="line">        gsl_vector_set(xi, 0, samples[i].theta);</div>
<div class="line">        gsl_vector_set(xi, 1, samples[i].phi);</div>
<div class="line"></div>
<div class="line">        <span class="comment">// Evaluate the output as the mean of the images of the sigma points</span></div>
<div class="line">        <span class="comment">//ukf_evaluate(p, s, my_func,xi,yi);</span></div>
<div class="line">        <span class="comment">// Or directly with the function</span></div>
<div class="line">        my_func(s.w,xi, yi);</div>
<div class="line">        outfile &lt;&lt; gsl_vector_get(xi, 0) &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; gsl_vector_get(xi, 1) &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; gsl_vector_get(yi, 0) &lt;&lt; <span class="stringliteral">&quot; &quot;</span> &lt;&lt; gsl_vector_get(yi,1) &lt;&lt; std::endl;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    outfile.close();</div>
<div class="line"></div>
<div class="line">    <span class="comment">/***********************************************/</span></div>
<div class="line">    <span class="comment">/****            Free the memory            ****/</span></div>
<div class="line">    <span class="comment">/***********************************************/</span></div>
<div class="line"></div>
<div class="line">    <a name="a15"></a><a class="code" href="namespaceukf_1_1parameter.html#a3edd781b5248176b7404889c96e6a962">ukf_free</a>(p,s);</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>
